// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   check_ok.java

package ecommerce.purchase;

import include.get_sql.getInsertSql;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;
import validata.ValidataTag;

public class check_ok extends HttpServlet
{

	public check_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		try
		{
			HttpSession dbSession = request.getSession();
			JspFactory _jspxFactory = JspFactory.getDefaultFactory();
			javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
			javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
			HttpSession session = request.getSession();
			nseer_db_backup1 design_db = new nseer_db_backup1(dbApplication);
			ValidataNumber validata = new ValidataNumber();
			ValidataTag vt = new ValidataTag();
			counter count = new counter(dbApplication);
			getInsertSql getInsertSql = new getInsertSql();
			if (design_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String config_id = request.getParameter("config_id");
				String product_ID = request.getParameter("product_ID");
				String responsible_person_ID = "";
				String responsible_person_name = "";
				String fileKind_chain = request.getParameter("fileKind_chain");
				String chain_id = Divide1.getId(fileKind_chain);
				String chain_name = Divide1.getName(fileKind_chain);
				String product_name = request.getParameter("product_name");
				String factory_name = request.getParameter("factory_name");
				String type = request.getParameter("type");
				String product_class = request.getParameter("product_class");
				String product_nick = request.getParameter("product_nick");
				String twin_name = request.getParameter("twin_name");
				String twin_ID = request.getParameter("twin_ID");
				String personal_unit = request.getParameter("personal_unit");
				String personal_value = request.getParameter("personal_value");
				if (personal_value.equals(""))
					personal_value = "0.00";
				personal_value = personal_value.replaceAll(",", "");
				String warranty = request.getParameter("warranty");
				String lifecycle = request.getParameter("lifecycle");
				String amount_unit = request.getParameter("amount_unit");
				String register = request.getParameter("register");
				String bodyc = new String(request.getParameter("provider_group").getBytes("UTF-8"), "UTF-8");
				String provider_group = exchange.toHtml(bodyc);
				String bodya = new String(request.getParameter("product_describe").getBytes("UTF-8"), "UTF-8");
				String product_describe = exchange.toHtml(bodya);
				String bodyb = new String(request.getParameter("promotion2").getBytes("UTF-8"), "UTF-8");
				String promotion2 = exchange.toHtml(bodyb);
				String bodyd = new String(request.getParameter("opinion2").getBytes("UTF-8"), "UTF-8");
				String opinion2 = exchange.toHtml(bodyd);
				String checker_ID = request.getParameter("checker_ID");
				String checker = request.getParameter("checker");
				String check_time = request.getParameter("check_time");
				String list_price2 = request.getParameter("list_price");
				StringTokenizer tokenTO4 = new StringTokenizer(list_price2, ",");
				String list_price;
				String list_price1;
				for (list_price = ""; tokenTO4.hasMoreTokens(); list_price = (new StringBuilder(String.valueOf(list_price))).append(list_price1).toString())
					list_price1 = tokenTO4.nextToken();

				String cost_price2 = request.getParameter("cost_price");
				StringTokenizer tokenTO5 = new StringTokenizer(cost_price2, ",");
				String cost_price;
				String cost_price1;
				for (cost_price = ""; tokenTO5.hasMoreTokens(); cost_price = (new StringBuilder(String.valueOf(cost_price))).append(cost_price1).toString())
					cost_price1 = tokenTO5.nextToken();

				int n = 0;
				if (!validata.validata(list_price) || Double.parseDouble(list_price) < 0.0D)
					n++;
				if (!validata.validata(cost_price) || Double.parseDouble(cost_price) < 0.0D)
					n++;
				String sql6 = (new StringBuilder("select * from ecommerce_workflow where object_ID='")).append(product_ID).append("' and type_id='03' and ((check_tag='0' and config_id<'").append(config_id).append("') or (check_tag='1' and config_id='").append(config_id).append("'))").toString();
				ResultSet rs6 = design_db.executeQuery(sql6);
				if (!rs6.next() && vt.validata((String)session.getAttribute("unit_db_name"), "design_file", "product_ID", product_ID, "excel_tag2").equals("1"))
				{
					if (n == 0)
					{
						String sql2 = (new StringBuilder("select * from design_config_file_kind where file_id='")).append(chain_id).append("'").toString();
						ResultSet rs2 = design_db.executeQuery(sql2);
						if (rs2.next())
						{
							String lately_change_time = request.getParameter("lately_change_time");
							String file_change_amount = request.getParameter("file_change_amount");
							int change_amount = Integer.parseInt(file_change_amount) + 1;
							String column_group = getInsertSql.sql((String)dbSession.getAttribute("unit_db_name"), "design_file");
							sql6 = (new StringBuilder("select * from ecommerce_workflow where object_ID='")).append(product_ID).append("' and config_id<'").append(config_id).append("' and type_id='03'").toString();
							rs6 = design_db.executeQuery(sql6);
							if (!rs6.next())
							{
								String sqloo = (new StringBuilder("select * from design_file where product_ID='")).append(product_ID).append("'").toString();
								ResultSet rsoo = design_db.executeQuery(sqloo);
								if (rsoo.next())
								{
									String sqll = (new StringBuilder("insert into design_file_dig(CHAIN_ID,CHAIN_NAME,PRODUCT_ID,PRODUCT_NAME,PRODUCT_NICK,PRODUCT_CLASS,TYPE,AMOUNT_UNIT,PRODUCT_DESCRIBE,FACTORY_NAME,FACTORY_ID,PROVIDER_GROUP,PHOTO1,PHOTO2,WARRANTY,LIST_PRICE,COST_PRICE,REAL_COST_PRICE,LIFECYCLE,PERSONAL_UNIT,PERSONAL_VALUE,TWIN_NAME,TWIN_ID,REMARK,CHECK_TAG,ACHIEVEMENT_SUM,ATTACHMENT_NAME,RETURN_SUM,RETURN_AMOUNT,FILE_CHANGE_AMOUNT,USED_PRODUCT_NAME,RESPONSIBLE_PERSON_NAME,RESPONSIBLE_PERSON_ID,REGISTER,CHECKER,CHANGER,REGISTER_ID,CHECKER_ID,CHANGER_ID,REGISTER_TIME,CHECK_TIME,CHANGE_TIME,LATELY_CHANGE_TIME,LATELY_TRADE_TIME,DELETE_TIME,RECOVERY_TIME,MODIFY_TAG,EXCEL_TAG,EXCEL_TAG2,EXCEL_TAG3,EXCEL_TAG4,DESIGN_MODULE_TAG,DESIGN_PROCEDURE_TAG,DESIGN_CELL_TAG,RECOMMEND_PROVIDER_TAG,PRICE_CHANGE_TAG,PRICE_ALARM_TAG,promotion,opinion,promotion2,opinion2,promotion3,opinion3,promotion4,opinion4) values('")).append(rsoo.getString("CHAIN_ID")).append("','").append(rsoo.getString("CHAIN_NAME")).append("','").append(rsoo.getString("PRODUCT_ID")).append("','").append(rsoo.getString("PRODUCT_NAME")).append("','").append(rsoo.getString("PRODUCT_NICK")).append("','").append(rsoo.getString("PRODUCT_CLASS")).append("','").append(rsoo.getString("TYPE")).append("','").append(rsoo.getString("AMOUNT_UNIT")).append("','").append(rsoo.getString("PRODUCT_DESCRIBE")).append("','").append(rsoo.getString("FACTORY_NAME")).append("','").append(rsoo.getString("FACTORY_ID")).append("','").append(rsoo.getString("PROVIDER_GROUP")).append("','").append(rsoo.getString("PHOTO1")).append("','").append(rsoo.getString("PHOTO2")).append("','").append(rsoo.getString("WARRANTY")).append("','").append(rsoo.getString("LIST_PRICE")).append("','").append(rsoo.getString("COST_PRICE")).append("','").append(rsoo.getString("REAL_COST_PRICE")).append("','").append(rsoo.getString("LIFECYCLE")).append("','").append(rsoo.getString("PERSONAL_UNIT")).append("','").append(rsoo.getString("PERSONAL_VALUE")).append("','").append(rsoo.getString("TWIN_NAME")).append("','").append(rsoo.getString("TWIN_ID")).append("','").append(rsoo.getString("REMARK")).append("','").append(rsoo.getString("CHECK_TAG")).append("','").append(rsoo.getString("ACHIEVEMENT_SUM")).append("','").append(rsoo.getString("ATTACHMENT_NAME")).append("','").append(rsoo.getString("RETURN_SUM")).append("','").append(rsoo.getString("RETURN_AMOUNT")).append("','").append(rsoo.getString("FILE_CHANGE_AMOUNT")).append("','").append(rsoo.getString("USED_PRODUCT_NAME")).append("','").append(rsoo.getString("RESPONSIBLE_PERSON_NAME")).append("','").append(rsoo.getString("RESPONSIBLE_PERSON_ID")).append("','").append(rsoo.getString("REGISTER")).append("','").append(rsoo.getString("CHECKER")).append("','").append(rsoo.getString("CHANGER")).append("','").append(rsoo.getString("REGISTER_ID")).append("','").append(rsoo.getString("CHECKER_ID")).append("','").append(rsoo.getString("CHANGER_ID")).append("','").append(rsoo.getString("REGISTER_TIME")).append("','").append(rsoo.getString("CHECK_TIME")).append("','").append(rsoo.getString("CHANGE_TIME")).append("','").append(rsoo.getString("LATELY_CHANGE_TIME")).append("','").append(rsoo.getString("LATELY_TRADE_TIME")).append("','").append(rsoo.getString("DELETE_TIME")).append("','").append(rsoo.getString("RECOVERY_TIME")).append("','").append(rsoo.getString("MODIFY_TAG")).append("','").append(rsoo.getString("EXCEL_TAG")).append("','").append(rsoo.getString("EXCEL_TAG2")).append("','").append(rsoo.getString("EXCEL_TAG3")).append("','").append(rsoo.getString("EXCEL_TAG4")).append("','").append(rsoo.getString("DESIGN_MODULE_TAG")).append("','").append(rsoo.getString("DESIGN_PROCEDURE_TAG")).append("','").append(rsoo.getString("DESIGN_CELL_TAG")).append("','").append(rsoo.getString("RECOMMEND_PROVIDER_TAG")).append("','").append(rsoo.getString("PRICE_CHANGE_TAG")).append("','").append(rsoo.getString("PRICE_ALARM_TAG")).append("','").append(rsoo.getString("promotion")).append("','").append(rsoo.getString("opinion")).append("','").append(rsoo.getString("promotion2")).append("','").append(rsoo.getString("opinion2")).append("','").append(rsoo.getString("promotion3")).append("','").append(rsoo.getString("opinion3")).append("','").append(rsoo.getString("promotion4")).append("','").append(rsoo.getString("opinion4")).append("')").toString();
									design_db.executeUpdate(sqll);
								}
							}
							String sql = (new StringBuilder("update design_file set chain_id='")).append(chain_id).append("',chain_name='").append(chain_name).append("',product_ID='").append(product_ID).append("',product_name='").append(product_name).append("',factory_name='").append(factory_name).append("',product_class='").append(product_class).append("',type='").append(type).append("',twin_name='").append(twin_name).append("',twin_ID='").append(twin_ID).append("',personal_unit='").append(personal_unit).append("',personal_value='").append(personal_value).append("',warranty='").append(warranty).append("',lifecycle='").append(lifecycle).append("',product_nick='").append(product_nick).append("',list_price='").append(list_price).append("',cost_price='").append(cost_price).append("',register='").append(register).append("',provider_group='").append(provider_group).append("',product_describe='").append(product_describe).append("',responsible_person_name='").append(responsible_person_name).append("',responsible_person_ID='").append(responsible_person_ID).append("',amount_unit='").append(amount_unit).append("',promotion2='").append(promotion2).append("',opinion2='").append(opinion2).append("' where product_ID='").append(product_ID).append("'").toString();
							design_db.executeUpdate(sql);
							sql = (new StringBuilder("update ecommerce_workflow set check_tag='1',checker_ID='")).append(checker_ID).append("',checker='").append(checker).append("',check_time='").append(check_time).append("' where object_ID='").append(product_ID).append("' and config_id='").append(config_id).append("' and type_id='03'").toString();
							design_db.executeUpdate(sql);
							sql6 = (new StringBuilder("select * from ecommerce_workflow where object_ID='")).append(product_ID).append("' and check_tag='0' and type_id='03'").toString();
							rs6 = design_db.executeQuery(sql6);
							if (!rs6.next())
							{
								sql = (new StringBuilder("update design_file set excel_tag2='3' where product_ID='")).append(product_ID).append("'").toString();
								design_db.executeUpdate(sql);
							}
							response.sendRedirect((new StringBuilder("ecommerce/purchase/check_choose_attachment.jsp?product_ID=")).append(product_ID).toString());
						} else
						{
							response.sendRedirect((new StringBuilder("ecommerce/purchase/check_ok_a.jsp?product_ID=")).append(product_ID).append("&config_id=").append(config_id).toString());
						}
					} else
					{
						response.sendRedirect((new StringBuilder("ecommerce/purchase/check_ok_b.jsp?product_ID=")).append(product_ID).append("&config_id=").append(config_id).toString());
					}
				} else
				{
					response.sendRedirect("ecommerce/purchase/check_ok_c.jsp");
				}
				design_db.commit();
				design_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
